#include "tcl_mtk_dtv_tv.h"
TCL_MTK_DTV_TV::TCL_MTK_DTV_TV()
{

}

TCL_MTK_DTV_TV::~TCL_MTK_DTV_TV()
{

}

int TCL_MTK_DTV_TV::Read_Data(QDataStream &in)
{

    in>>ui4_ch_val
       >>ps_name
        >>ui4_class
          >>ui4_type
        >>ui4_freq
      >>ui4_isfav
      >>ui4_isskip;
    return 0;
}

int TCL_MTK_DTV_TV::Write_Data(QDataStream &out)
{
  out<<ui4_ch_val
     <<ps_name
     <<ui4_class
       <<ui4_type
     <<ui4_freq
     <<ui4_isfav
     <<ui4_isskip;

    return 0;
}


void TCL_MTK_DTV_TV::Set_Data(int order,QVariant value)
{
    bool flag=false;
    bool *ok=&flag;
     switch(order)
     {

     case 0:
      ui4_ch_val=value.toUInt(ok);
      STRING_TRAN_ERROR_0;
      break;
     case 1:
      ps_name=value.toString();
      break;
     case 2:
         if(0==value.toString().compare("DTV-T"))
             ui4_class=0;
         else if(0==value.toString().compare("DTV-C"))
             ui4_class=1;
         else if(0==value.toString().compare("DTV-S/S2"))
             ui4_class=2;
         else
             ui4_class=3;
      STRING_TRAN_ERROR_0;
      break;
     case 3:
         if(strcmp("D",value.toString().toStdString().c_str()))
             ui4_type=1;
         else if(strcmp("R",value.toString().toStdString().c_str()))
             ui4_type=2;
         else if(strcmp("T",value.toString().toStdString().c_str()))
             ui4_type=3;
         else if(strcmp("U",value.toString().toStdString().c_str()))
             ui4_type=4;
         else
             ui4_type=5;
         break;
     case 4:
         ui4_freq=value.toUInt(ok);
         STRING_TRAN_ERROR_0;
     case 5:
         ui4_isfav=value.toUInt(ok);
         STRING_TRAN_ERROR_0;
         break;
      case 6:
         ui4_isskip=value.toUInt(ok);
         STRING_TRAN_ERROR_0;
         break;
     default:
      //qDebug("In MTK DTV set_Data:order error!");
         Q_ASSERT(order<NUM_DTV_ITEM&&order>=0);

     }
}



int TCL_MTK_DTV_TV::Count_Item()
{
    return NUM_DTV_ITEM;
}

QString TCL_MTK_DTV_TV::Get_Item(int i)
{
    Q_ASSERT(i>=0&&i<NUM_DTV_ITEM);
    QString tmp;
    switch(i)
    {
        case 0:
         tmp.setNum(ui4_ch_val);
         break;
        case 1:
         tmp=ps_name;
         break;
        case 2:
            tmp.setNum(ui4_class);
            break;
    case 3:
        tmp.setNum(ui4_type);
        break;
        case 4:
            tmp.setNum(ui4_freq);
            break;
        case 5:
            tmp.setNum(ui4_isfav);
            break;
        case 6:
            tmp.setNum(ui4_isskip);
            break;

        default:
            tmp=" ";
            break;
    }
    return tmp;
}


void TCL_MTK_DTV_TV::Get_Data(QList<QString> *ch_data)
{
    QString tmp="";
    tmp.setNum(ui4_ch_val);
    ch_data->append(tmp);
    ch_data->append(ps_name);
    if(ui4_class==0)
        tmp="DTV-T";
    else if(ui4_class==1)
        tmp="DTV-C";
    else if(ui4_class==2)
        tmp="DTV-S/S2";
    else
        tmp="DTV-T2";
    ch_data->append(tmp);
    switch(ui4_type)
    {
        case 1:
            tmp="D";
            break;
        case 2:
            tmp="R";
            break;
        case 3:
            tmp="T";
            break;
        default:
            tmp="U";
            break;
    }
    ch_data->append(tmp);
    tmp.setNum(ui4_freq);
    ch_data->append(tmp);
    tmp.setNum(ui4_isfav);
    ch_data->append(tmp);
    tmp.setNum(ui4_isskip);
     ch_data->append(tmp);
}


void TCL_MTK_DTV_TV::Set_Data(QList<QString> &ch_data)
{
    Q_ASSERT(ch_data.size()==7);
    bool flag=false;
    bool *ok=&flag;
    ui4_ch_val=ch_data.at(0).toUInt(ok);
    STRING_TRAN_ERROR_0;
    ps_name=ch_data.at(1);
    ui4_class=ch_data.at(2).toUInt(ok);
    STRING_TRAN_ERROR_0;
    ui4_type=ch_data.at(3).toUInt(ok);
    STRING_TRAN_ERROR_0;
    ui4_freq=ch_data.at(4).toUInt(ok);
    STRING_TRAN_ERROR_0;
    ui4_isfav=ch_data.at(5).toUInt(ok);
    STRING_TRAN_ERROR_0;
    ui4_isskip=ch_data.at(6).toUInt(ok);
    STRING_TRAN_ERROR_0;


}
